package com.atguigu.jedis.demos;

import redis.clients.jedis.Jedis;

import java.util.Set;

/**
 * Created by Smexy on 2022/5/20
 */
public class SetDemo {

    public static void main(String[] args) {

        //构建Jedisclient

        Jedis jedis = new Jedis("hadoop104", 6379);

        //写set
        jedis.sadd("set1","1","2","3","4");

        // 读set
        Set<String> response = jedis.smembers("set1");

        //读一个不存在key的set,返回 set(),并不是null
        // 如果 response2.foreach(): 不会报空指针异常
        Set<String> response2 = jedis.smembers("set2");

        System.out.println(response);
        System.out.println(response2);

        jedis.close();

    }
}
